package com.zhongxi.guoyuan.adapter.rewardCoin;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import com.zhongxi.guoyuan.fragment.hmfragment.BestPriceFragment;
import com.zhongxi.guoyuan.fragment.hmfragment.NewGoodsFragment;
import com.zhongxi.guoyuan.fragment.hmfragment.SalesGoodsFragment;
import com.zhongxi.guoyuan.view.rewardCoin.ItemFragmentFactory;

/**
 * Created by Administrator on 2017/10/11.
 */

public class TabNewAdapter extends FragmentStatePagerAdapter {

    private String trim;
    private String id;

    public TabNewAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        String title = "最新";
        switch (position) {
            case 0:
                title = "最新";
                break;
            case 1:
                title = "销量";
                break;
            case 2:
                title = "最惠";
                break;
        }
        return title;
    }

    @Override
    public Fragment getItem(int position) {
        return ItemFragmentFactory.creatItem(position,id,trim);
    }

//    @Override
//    public Object instantiateItem(ViewGroup container, int position) {
//        if (position == 0) {
//            NewGoodsFragment newGoodsFragment = (NewGoodsFragment) super.instantiateItem(container, position);
////            newGoodsFragment.setUpdatePrimary(id, trim);
//            return newGoodsFragment;
//        } else if (position == 1) {
//            SalesGoodsFragment goodsFragment = (SalesGoodsFragment) super.instantiateItem(container, position);
////            goodsFragment.setUpdatePrimary(id, trim);
//            return goodsFragment;
//        } else if (position == 2) {
//            BestPriceFragment bestPriceFragment = (BestPriceFragment) super.instantiateItem(container, position);
////            bestPriceFragment.setUpdatePrimary(id, trim);
//            return bestPriceFragment;
//        }
//        return super.instantiateItem(container, position);
//    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    public void setItemPrimary(String id, String trim) {
        this.id = id;
        this.trim = trim;
    }
}
